package tag;

import java.io.IOException;
import java.io.StringWriter;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class OrgTag extends SimpleTagSupport {
	private int orgId;//组织Id
	
	@Override
	public void doTag() throws JspException, IOException {
		//获取session中的属性
		Integer org_id = (Integer) getJspContext().getAttribute("orgId", PageContext.SESSION_SCOPE);
		
		if(org_id != null) {
			//具有该org权限则数据标签体内容
			if(orgId == org_id) {
				//JSP输出流
				JspWriter out = getJspContext().getOut();
				//标签内容缓存
				StringWriter sw = new StringWriter();
				//获得标签内容
				getJspBody().invoke(sw);
				//输入标签内容
				out.print(sw.toString());
			}
		}
	}

	//getter setter
	public int getOrgId() {
		return orgId;
	}
	public void setOrgId(int orgId) {
		this.orgId = orgId;
	}
}